package com.hdit.mgr
{
	
	import flash.events.IEventDispatcher;
	
	import mx.events.ResourceEvent;
	import mx.logging.Log;
	import mx.resources.IResourceManager;

	/**
	 * 本地化语言模块管理
	 **/
	public class LanguageMgr
	{
		private static var _resMgr:IResourceManager;
		private static var _langFlag:String;
		public function LanguageMgr()
		{
		}
		
		/**
		 * 初始化语言管理模块
		 * @param url 系统默认加载的语言模块
		 * @param resourceManager
		 **/
		public static function init(url:String,langFlag:String,resourceManager:IResourceManager):void
		{
			LogMgr.info("加载"+langFlag+"语言模块...");
			_resMgr=resourceManager;
			_langFlag=langFlag;
			load(url,_langFlag,_resMgr);
		}
		
		/**
		 * 加载本地语言模块
		 * @param url 语言模块路径
		 * @param langFlag 语言环境字符串
		 **/
		public static function load(url:String,langFlag:String,resourceManager:IResourceManager):void
		{
			_langFlag=langFlag;
			var eventDispatcher:IEventDispatcher = resourceManager.loadResourceModule(url,true);
			eventDispatcher.addEventListener(ResourceEvent.COMPLETE, completeHandler);
			eventDispatcher.addEventListener(ResourceEvent.PROGRESS,progressHandler);
		}
		
		private static function progressHandler(e:ResourceEvent):void
		{
			var loadInfo:String=_langFlag+"语言包加载进度:"+((e.bytesLoaded/e.bytesTotal*100)>>0).toString()+"%";
			LogMgr.info(loadInfo);
		}
			
		private static function completeHandler(event:ResourceEvent):void
		{
			_resMgr.localeChain = [_langFlag];
			LogMgr.info("加载"+_langFlag+"语言模块完毕!");
		}
	}
}